package com.qingmi.farmer.viewmodel;

import android.databinding.ObservableField;

import com.qingmi.farmer.data.model.Buyer;
import com.qingmi.farmer.data.model.Grain;
import com.qingmi.farmer.data.model.GrainDemand;
import com.wjjun.basemvpvm.viewmodel.BaseViewModel;

/**
 * 收购
 * Created by 67535 on 2018/5/1.
 */
public class GrainDemandItemViewModel extends BaseViewModel {

    public String id;

    public Buyer buyer;

    public Grain grain;

    public final ObservableField<String> variety = new ObservableField<>();

    public final ObservableField<String> level = new ObservableField<>();

    public final ObservableField<Double> price = new ObservableField<>(0.0);

    public final ObservableField<String> buyerName = new ObservableField<>();

    public GrainDemandItemViewModel(GrainDemand grainDemand) {
        id = grainDemand.getId();
        grain = grainDemand.getGrain();
        buyer = grainDemand.getBuyer();

        if( grainDemand.getGrain() != null){
            this.variety.set(grainDemand.getGrain().getGrainTypeName());
            this.level.set(grainDemand.getGrain().getLevelName());
        }

        this.price.set(grainDemand.getPrice());

        if (grainDemand.getPrice() == 0 && grainDemand.getDeliveries() != null && !grainDemand.getDeliveries().isEmpty()) {
            price.set(grainDemand.getDeliveries().get(0).getPrice());
        }

        if (grainDemand.getBuyer() != null) {
            this.buyerName.set(grainDemand.getBuyer().getBuyerName());
        }
    }

    @Override
    public String toString() {
        return id;
    }
}
